﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Control.Bus;

namespace QuanLyKho
{
    public partial class FrmQuanLyXuat : Form
    {
        List<BusExportBill> Bills = new List<BusExportBill>();
        BusStaff staff = new BusStaff()
        {
            ID = 1,
            UserName = "admin",
            PassWord = "admin"
        };
        public FrmQuanLyXuat(BusStaff staff)
        {
            InitializeComponent();
            this.staff = staff;
            dataGridView1.AutoGenerateColumns = false;
            Bills = BusExportBill.GetListByDateAndStaff(dateTimePicker1.Value, staff);
            
                ChangeDatasource();
        }

        private void btThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            
            Bills = BusExportBill.GetListByDateAndStaff(dateTimePicker1.Value, staff);
                ChangeDatasource();
        }

        private void ChangeDatasource()
        {
  
            dataGridView1.DataSource = null;

            dataGridView1.DataSource = Bills;
        }

        private void btSua_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count != 0)
            {
                BusExportBill Bill = Bills[dataGridView1.SelectedRows[0].Index];
                FrmExport frm = new FrmExport(Bill, staff);
                frm.Show();
            }
        }

        private void btXuat_Click(object sender, EventArgs e)
        {
            BusExportBill Bill = BusExportBill.GetBillThuongByDateAndStaff(dateTimePicker1.Value, this.staff);
            if (Bill.ID == -1)
            {
                Bill.Date = DateTime.Now;
                Bill.Staff = this.staff;
                Bill.BillName = "Thường";
                Bill.BillCode = null;
                Bill.Insert();
            }
            FrmExport frm = new FrmExport(Bill, this.staff);
            frm.ShowDialog();
            Bills = BusExportBill.GetListByDateAndStaff(dateTimePicker1.Value, staff);
            ChangeDatasource();
        }

        private void btXuatBO_Click(object sender, EventArgs e)
        {
            FrmXuatBO frm = new FrmXuatBO(dateTimePicker1.Value, this.staff);
            frm.ShowDialog();
            Bills = BusExportBill.GetListByDateAndStaff(dateTimePicker1.Value, staff);
            ChangeDatasource();

        }

        private void dataGridView1_DoubleClick(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count != 0)
            {
                BusExportBill Bill = Bills[dataGridView1.SelectedRows[0].Index];
                FrmExport frm = new FrmExport(Bill, staff);
                frm.Show();
            }
        }


    }
}
